package com.qf;

/**
 *通过继承Thread来实现
 */
class ThreadDemo extends Thread{
    private String threadName;

    ThreadDemo( String name) {
        threadName = name;
        System.out.println("Creating " +  threadName );
    }

    public void run() {
        System.out.println("Running " +  threadName );
        try {
            for(int i = 4; i > 0; i--) {
                System.out.println("Thread: " + threadName + ", " + i);
                // 让线程睡眠一会
                Thread.sleep(50);
            }
        }catch (InterruptedException e) {
            System.out.println("Thread " +  threadName + " interrupted.");
        }
        System.out.println("Thread " +  threadName + " exiting.");
    }
}


public class TestThread2 {

    public static void main(String[] args) {
        ThreadDemo t1=new ThreadDemo("thread-1");
        t1.start();
        ThreadDemo t2=new ThreadDemo("thread-2");
        t2.start();
    }
}
